cmake_minimum_required(VERSION 3.2)
project(pocelain)
enable_testing()
set(CMAKE_CXX_STANDARD 11)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
    set(EMSCRIPTEN TURE)
    #set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
endif()

#find_package(PkgConfig REQUIRED)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

include_directories(./thirdparty/stb)

IF(EMSCRIPTEN)
    include_directories(./thirdparty/glm)
ELSE(EMSCRIPTEN)

    include_directories(./thirdparty/glew-2.1.0/include)
    include_directories(./thirdparty/glfw/include)
    include_directories(./thirdparty/freeglut/include)
    IF(APPLE)
        SET(EXTRA_LIBS ${EXTRA_LIBS} glfw GLEW)
        set(CMAKE_MACOSX_RPATH 1)
        # Use system glfw3 and glew
        #FIND_PACKAGE(GLFW3 REQUIRED )
        #FIND_PACKAGE(GLEW REQUIRED )
        #if(GLFW3_FOUND)
        #    message("GLFW3 Found")
        #    SET(EXTRA_LIBS ${EXTRA_LIBS} glfw )
        #endif(GLFW3_FOUND)
        #if(GLEW_FOUND)
        #    FIND_PATH(GLEW_INCLUDE_DIR GL/glew.h )
        #    FIND_LIBRARY(GLEW_LIBRARY glew )
        #    message("GLEW Found:" ${GLEW_INCLUDE_DIR})
        #    include_directories(${GLEW_INCLUDE_DIR})
        #    SET(EXTRA_LIBS ${EXTRA_LIBS} ${GLEW_LIBRARY} )
        #endif(GLEW_FOUND)

        FIND_LIBRARY(OpenGL_LIBRARY OpenGL )
        SET(EXTRA_LIBS ${EXTRA_LIBS} ${OpenGL_LIBRARY} )
    ENDIF (APPLE)

    IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
        #FIND_PACKAGE(GLUT REQUIRED)
        #pkg_search_module(GLU REQUIRED glu)
        pkg_search_module(OPENGL REQUIRED gl)
        SET(EXTRA_LIBS ${EXTRA_LIBS} ${GLU_LIBRARIES} ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES} m)
    ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
    if(WIN32)
        message(STATUS "Hello world")
        link_directories(./thirdparty/glew-2.1.0/lib/Release/x64)
        link_directories(./thirdparty/freeglut/out/install/x64-${CMAKE_BUILD_TYPE}/lib)
        SET(EXTRA_LIBS ${EXTRA_LIBS} glfw glew32 )
    else()
        link_directories(./thirdparty/glew-2.1.0/lib)
    endif()

ENDIF(EMSCRIPTEN)

file(GLOB_RECURSE POCELAIN_LIB_SRCS src/*.h src/*.hpp src/*.cpp)
add_library(${PROJECT_NAME} STATIC ${POCELAIN_LIB_SRCS})
target_link_libraries(${PROJECT_NAME} ${EXTRA_LIBS})

add_definitions(-DGL_SILENCE_DEPRECATION -DSTB_IMAGE_IMPLEMENTATION)

set(EXTRA_LIBS ${EXTRA_LIBS} ${PROJECT_NAME})
add_subdirectory(./thirdparty/glfw/)
#add_subdirectory(./thirdparty/freeglut/)
add_subdirectory(./examples/)
add_subdirectory(./test/)
